package com.boda.common.util;

import java.math.BigDecimal;

public class ObjUtil {
    public static String toString(Object obj) {
        if (obj == null) {
            return "";
        }
        return String.valueOf(obj);
    }

    public static int toInt(Object obj) {
        if (obj == null) {
            return 0;
        }
        if (obj instanceof Integer) {
            return (int) obj;
        } else if (obj instanceof BigDecimal) {
            return ((BigDecimal) obj).intValue();
        } else if (obj instanceof String) {
            return Integer.parseInt(toString(obj));
        } else {
            return 0;
        }
    }
}
